package instruction

import (
	"gitee.com/microwww/jvm-go/jvm/rtda"
)

// 类型转换指令

type I2L struct {
	Noop
}

func (f *I2L) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopInt()
	v := int64(i)
	stack.PushLong(v)
}

type I2F struct {
	Noop
}

func (f *I2F) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopInt()
	v := float32(i)
	stack.PushFloat(v)
}

type I2D struct {
	Noop
}

func (f *I2D) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopInt()
	v := float64(i)
	stack.PushDouble(v)
}

type L2I struct {
	Noop
}

func (f *L2I) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopLong()
	v := int32(i)
	stack.PushInt(v)
}

type L2F struct {
	Noop
}

func (f *L2F) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopLong()
	v := float32(i)
	stack.PushFloat(v)
}

type L2D struct {
	Noop
}

func (f *L2D) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopLong()
	v := float64(i)
	stack.PushDouble(v)
}

type F2I struct {
	Noop
}

func (f *F2I) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopFloat()
	v := int32(i)
	stack.PushInt(v)
}

type F2L struct {
	Noop
}

func (f *F2L) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopFloat()
	v := int64(i)
	stack.PushLong(v)
}

type F2D struct {
	Noop
}

func (f *F2D) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	i := stack.PopFloat()
	v := float64(i)
	stack.PushDouble(v)
}

type D2I struct {
	Noop
}

func (f *D2I) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	v := stack.PopDouble()
	i := int32(v)
	stack.PushInt(i)
}

type D2L struct {
	Noop
}

func (f *D2L) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	v := stack.PopDouble()
	i := int64(v)
	stack.PushLong(i)
}

type D2F struct {
	Noop
}

func (f *D2F) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	v := stack.PopDouble()
	i := float32(v)
	stack.PushFloat(i)
}

type I2B struct {
	Noop
}

func (f *I2B) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	v := stack.PopInt()
	i := byte(v)
	stack.PushInt(int32(i))
}

type I2C struct {
	Noop
}

func (f *I2C) Execute(fm *rtda.MethodFrame) {
	// int32 -> rune
}

type I2S struct {
	Noop
}

func (f *I2S) Execute(fm *rtda.MethodFrame) {
	stack := fm.OperationStack()
	v := stack.PopInt()
	i := int16(v)
	stack.PushInt(int32(i))
}
